package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.photomovie.PhotoMovieFactory;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.PicConvertActivity;
import flc.ast.adapter.PicTurnAdapter;
import flc.ast.bean.PicTurnBean;
import flc.ast.databinding.FragmentPicFilterBinding;
import stark.common.basic.base.BaseNoModelFragment;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link PicTurnFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PicTurnFragment extends BaseNoModelFragment<FragmentPicFilterBinding>{

    private PicTurnAdapter picTurnAdapter;
    private int oldPosition=0;

    @Override
    protected int onCreate() {
        return R.layout.fragment_pic_filter;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        picTurnAdapter.getItem(oldPosition).setSelect(false);
        oldPosition = position;
        picTurnAdapter.getItem(position).setSelect(true);
        picTurnAdapter.notifyDataSetChanged();
        //设置转场
        PicConvertActivity.mMoviePresenter.setTransfer(picTurnAdapter.getItem(position).getPhotoMovieType());
    }

    @Override
    protected void initData() {
        List<PicTurnBean> listPicTurn=new ArrayList<>();
        listPicTurn.add(new PicTurnBean(R.drawable.zc_zy,R.drawable.zc_zy2,"左右",true, PhotoMovieFactory.PhotoMovieType.HORIZONTAL_TRANS));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_sx,R.drawable.zc_sx2,"上下",false, PhotoMovieFactory.PhotoMovieType.VERTICAL_TRANS));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_dj,R.drawable.zc_dj2,"叠加",false,PhotoMovieFactory.PhotoMovieType.GRADIENT));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_ck,R.drawable.zc_ck2,"窗口",false,PhotoMovieFactory.PhotoMovieType.WINDOW));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_jb,R.drawable.zc_jb2,"渐变",false,PhotoMovieFactory.PhotoMovieType.THAW));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_sf,R.drawable.zc_sf2,"缩放",false,PhotoMovieFactory.PhotoMovieType.SCALE));
        listPicTurn.add(new PicTurnBean(R.drawable.zc_zh,R.drawable.zc_zh2,"转换",false,PhotoMovieFactory.PhotoMovieType.SCALE_TRANS));
        mDataBinding.rvPicFilterList.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.HORIZONTAL,false));
        picTurnAdapter=new PicTurnAdapter();
        picTurnAdapter.setList(listPicTurn);
        mDataBinding.rvPicFilterList.setAdapter(picTurnAdapter);
        picTurnAdapter.setOnItemClickListener(this);
    }
}